<?php
$username = $_POST['username'];
$arr =  array();
include_once 'conn.php';
sleep(0);
if(empty($username)){
    $arr['code'] = 1;
    $arr['mag'] = '用户名不能为空';
}else {
    //写sql语句
    $sql = "select 1 from info where username = '$username'";

//   执行sql语句
    $result = mysqli_query($conn,$sql);
    if(mysqli_num_rows($result)){
//        找到了此用户名，说明用户名被占用了
        $arr['code'] = 0;
        $arr['msg'] = '用户名被占用';

    }else{
        $arr['code'] = 2;
        $arr['msg'] = '用户名可用';

    }
}
echo json_encode($arr);
